package com.uatair.web.controller.business;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uatair.common.annotation.Log;
import com.uatair.common.core.controller.BaseController;
import com.uatair.common.core.domain.AjaxResult;
import com.uatair.common.enums.BusinessType;
import com.uatair.system.domain.TpPlatform;
import com.uatair.system.service.ITpPlatformService;
import com.uatair.common.utils.poi.ExcelUtil;
import com.uatair.common.core.page.TableDataInfo;

/**
 * 第三方平台信息Controller
 * 
 * @author uatair
 * @date 2025-06-20
 */
@Api(tags = "第三方平台信息")
@RestController
@RequestMapping("/system/platform")
public class TpPlatformController extends BaseController
{
    @Autowired
    private ITpPlatformService tpPlatformService;

    /**
     * 查询第三方平台信息列表
     */
    @ApiOperation("查询第三方平台信息列表")
    @PreAuthorize("@ss.hasPermi('system:platform:list')")
    @GetMapping("/list")
    public TableDataInfo list(TpPlatform tpPlatform)
    {
//        startPage();
        List<TpPlatform> list = tpPlatformService.selectTpPlatformList(tpPlatform);
        return getDataTable(list);
    }

    /**
     * 导出第三方平台信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:platform:export')")
    @Log(title = "第三方平台信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TpPlatform tpPlatform)
    {
        List<TpPlatform> list = tpPlatformService.selectTpPlatformList(tpPlatform);
        ExcelUtil<TpPlatform> util = new ExcelUtil<TpPlatform>(TpPlatform.class);
        util.exportExcel(response, list, "第三方平台信息数据");
    }
    @GetMapping("/tree")
    public AjaxResult tree() {
        return success(tpPlatformService.selectTpPlatformTree());
    }
    /**
     * 获取第三方平台信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:platform:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tpPlatformService.selectTpPlatformById(id));
    }

    /**
     * 新增第三方平台信息
     */
    @PreAuthorize("@ss.hasPermi('system:platform:add')")
    @Log(title = "第三方平台信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TpPlatform tpPlatform)
    {
        return toAjax(tpPlatformService.insertTpPlatform(tpPlatform));
    }

    /**
     * 修改第三方平台信息
     */
    @PreAuthorize("@ss.hasPermi('system:platform:edit')")
    @Log(title = "第三方平台信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TpPlatform tpPlatform)
    {
        return toAjax(tpPlatformService.updateTpPlatform(tpPlatform));
    }

    /**
     * 删除第三方平台信息
     */
    @PreAuthorize("@ss.hasPermi('system:platform:remove')")
    @Log(title = "第三方平台信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tpPlatformService.deleteTpPlatformByIds(ids));
    }

    /**
     * 更新第三方平台状态
     */
    @PutMapping("/updateStatus/{id}")
    public AjaxResult updateStatus(@PathVariable Long id, @RequestBody Map<String, String> params) {
        String status = params.get("status");
        int result = tpPlatformService.updateStatus(id, status);
        if (result > 0) {
            return AjaxResult.success("状态更新成功");
        } else {
            return AjaxResult.error("状态更新失败");
        }
    }
}
